package com.wz.leetcode.array;

/**
 * @Author : Wang Zhen.
 * @Date : Created in 8:21 2022/9/25
 * @Description :
 * @Modified By   :
 * @Version :
 */
public class N0011_ContainerWithMostWater {

    public static int maxArea(int[] height) {
        if (height == null || height.length < 2) {
            return 0;
        }
        int left = 0;
        int right = height.length - 1;
        int maxArea = 0;
        while (left < right) {
            maxArea = Math.max(maxArea, (right - left) * Math.min(height[left], height[right]));
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return maxArea;
    }

    public static void main(String[] args) {
        System.out.println(maxArea(new int[]{1,8,6,2,5,4,8,3,7}));
        System.out.println(maxArea(new int[]{1, 1}));
    }
}
